import React, {lazy, useEffect, useState, Suspense} from 'react';
import PropTypes from 'prop-types';


const OaTemplate = (props) => {
    const {comTemplateName, oaSubmit, formData} = props;
    // 动态加载组件的高阶组件
    let [LazyLoadedComponent, setLazyLoadedComponent] = useState(null)
    useEffect(() => {
        if (!comTemplateName) return
        setLazyLoadedComponent(lazy(() => import(`./businessOA/${comTemplateName}.tsx`)))
    }, [comTemplateName]);
    return (
        <div>
            <Suspense fallback={<div>Loading...</div>}>
                {LazyLoadedComponent ? <LazyLoadedComponent oaSubmit={oaSubmit} formData={formData}/> : null}
            </Suspense>
        </div>
    );
};
OaTemplate.propTypes = {
    comTemplateName: PropTypes.string.isRequired,
    oaSubmit:  PropTypes.func,
    formData:  PropTypes.Object,
};
export default OaTemplate;